﻿// ==================================================
// Copyright © 2016 杭州伯庸科技 版权所有
//
// 文 件 名：AddViewSpot
// 功能描述：
//
// 创建标识：Yu.Liang(俞 亮) 2018/3/8 14:33:07
//
// 修改标识：
// 修改描述：
// ==================================================

using Shine.Framework;
using SuperMap.Realspace;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Shine.Viewer
{
    public class AddViewSpot : BaseCommand
    {
        IApplication m_Application = null;
        //RealspaceBookmarkUserForm m_usf = null;
        ViewSpotListUserForm m_usf = null;
        Scene m_scene = null;

        public AddViewSpot()
        {
            base.m_caption = "添加视点";
            base.m_name = "AddViewSpot";
            base.m_toolTip = "添加视点";
            base.m_message = "添加视点";
            base.m_category = "Viewer";
        }

        public override void OnCreate(object hook)
        {
            if (m_Application == null)
            {
                m_Application = hook as IApplication;
                m_scene = (m_Application as IFramework).SceneControl.Scene;
            }
        }

        public override void OnClick()
        {
            //(m_Application as IFramework).DockManager.ActivateDockPanel("视点管理");
            m_usf = (m_Application as IFramework).DockManager.GetControlFromDockPanel("视点管理") as ViewSpotListUserForm;
            
            if (m_usf != null)
            {
                // 当前camera
                Camera ca = m_scene.Camera;
                string name = "未命名";
                string unicode = Shine.Viewer.BookMarkHelper.GetGuid();
                string bookmarkFile = System.IO.Directory.GetCurrentDirectory() + "\\ViewSpot\\" + unicode + ".jpg";
                this.m_scene.OutputScenePicture(bookmarkFile, 360, 200);

                RealspaceBookMarkStruck bk = new RealspaceBookMarkStruck
                {
                    ca = ca,
                    bkname = name,
                    bkfile = bookmarkFile,
                    bkunicode = unicode
                };

                m_usf.AddNewBookMark(bk);
            }
        }

        public override int Bitmap
        {
            get
            {
                string imgFile = Application.StartupPath + "\\Images\\" + GetType().Name + ".png";

                if (System.IO.File.Exists(imgFile) == false) return 0;

                return new Bitmap(Image.FromFile(imgFile)).GetHbitmap().ToInt32();
            }
        }

        public override bool Enabled
        {
            get { return (m_Application as IFramework).IsSceneCtlActive;}
        }
    }
}
